<template>
  <el-container class="layout-container">
    <el-aside :width="isCollapse ? '64px' : '220px'">
      <div class="logo">
        <img src="../assets/castle-logo.png" alt="Castle" class="logo-image" />
      </div>
      <el-menu
        :default-active="route.path"
        class="el-menu-vertical"
        :router="true"
        :collapse="isCollapse"
        background-color="#001529"
        text-color="#fff"
        active-text-color="#409EFF"
      >
        <el-menu-item index="/contracts">
          <span>基础列表页</span>
        </el-menu-item>
        <el-menu-item index="/contracts/table">
          <span>基础表单页</span>
        </el-menu-item>
        <el-menu-item index="/contracts/detail">
          <span>基础详情页</span>
        </el-menu-item>
        <el-menu-item index="/detail-panel">
          <span>AI生成页面</span>
        </el-menu-item>
        <el-menu-item index="/next-update">
          <span>下次更新</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    
    <el-container>
      <el-header>
        <div class="header-content">
          <div class="header-left">
            <el-icon class="toggle-sidebar" @click="isCollapse = !isCollapse">
              <Fold v-if="!isCollapse"/>
              <Expand v-else/>
            </el-icon>
            <el-input
              v-model="searchQuery"
              placeholder="请输入内容搜索"
              class="header-search"
            >
              <template #prefix>
                <el-icon><Search /></el-icon>
              </template>
            </el-input>
          </div>
          <el-dropdown>
            <span class="user-info">
              <el-avatar :size="32" />
              <span>Admin</span>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>Profile</el-dropdown-item>
                <el-dropdown-item>Settings</el-dropdown-item>
                <el-dropdown-item divided @click="handleLogout">Logout</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>
      
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { useRoute, useRouter } from 'vue-router'
import { ref } from 'vue'
import { Fold, Expand, Search } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

const route = useRoute()
const router = useRouter()
const isCollapse = ref(false)
const searchQuery = ref('')

const handleLogout = () => {
  // 清除登录状态
  localStorage.removeItem('isAuthenticated')
  ElMessage.success('Logout successful')
  // 跳转到登录页面
  router.push('/login')
}
</script>

<style scoped>
.layout-container {
  height: 100vh;
}

.logo {
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  background-color: #001529;
  gap: 10px;
}

.logo-image {
  height: 40px;
  width: auto;
  flex-shrink: 0;
}

.el-aside {
  background-color: #001529;
}

.el-menu {
  border-right: none;
}

.el-menu-item {
  height: 50px;
  line-height: 50px;
}

.el-menu-item:hover {
  background-color: #1890ff !important;
}

.el-menu-item.is-active {
  background-color: #1890ff !important;
}

.el-header {
  background-color: white;
  border-bottom: 1px solid #dcdfe6;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 20px;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
}

.header-content {
  display: flex;
  align-items: center;
  width: 100%;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-search {
  width: 250px;
  margin-right: 20px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.el-main {
  background-color: #f0f2f5;
  padding: 20px;
}

:deep(.el-menu-item .el-icon) {
  margin-right: 8px;
}

.toggle-sidebar {
  font-size: 20px;
  cursor: pointer;
  color: #606266;
}

.toggle-sidebar:hover {
  color: #409EFF;
}

.el-aside {
  transition: width 0.3s;
  overflow: hidden;
}

.logo {
  transition: all 0.3s;
}

.search-input {
  transition: all 0.3s;
}

.search-input.collapsed {
  width: 0;
  opacity: 0;
  margin: 0;
  padding: 0;
}

:deep(.search-input .el-input__wrapper) {
  background-color: rgba(255, 255, 255, 0.1);
  box-shadow: none;
  border: none;
}

:deep(.search-input .el-input__inner) {
  color: #fff;
}

:deep(.search-input .el-input__inner::placeholder) {
  color: rgba(255, 255, 255, 0.5);
}

:deep(.search-input .el-input__prefix-icon) {
  color: rgba(255, 255, 255, 0.5);
}

:deep(.header-search .el-input__wrapper) {
  background-color: #f5f7fa;
}

:deep(.header-search .el-input__inner::placeholder) {
  color: #909399;
}

:deep(.header-search .el-input__prefix-icon) {
  color: #909399;
}
</style> 